package com.csw.compose.ui.module.component.advanced

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.Button
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import com.csw.compose.theme.pagePadding
import com.csw.compose.ui.Destination
import com.csw.compose.ui.components.BodyText
import com.csw.compose.ui.components.LabelText
import com.csw.compose.ui.components.LargeSpacer
import com.csw.compose.ui.components.NormalSpacer
import com.csw.compose.ui.components.OlItem
import com.csw.compose.ui.components.PrimaryTitle
import com.csw.compose.ui.components.UlItem
import com.csw.compose.ui.module.BasePage

@Preview
@Composable
fun DropdownMenuPagePreview() {
    BasePage({}, "弹窗（DropdownMenu）") {
        DropdownMenuPage()
    }
}

class DropdownMenuPageData {
    companion object : Destination("DropdownMenuPage")
}

/**
 *[参考](https://developer.android.google.cn/develop/ui/compose/components/menu?hl=zh-cn)
 */
@Composable
fun DropdownMenuPage() {
    Column(
        modifier = Modifier
            .padding(horizontal = pagePadding)
            .verticalScroll(rememberScrollState())
    ) {
        PrimaryTitle("简介")
        BodyText("Divider 间隔线组件，有此组件，可不用Box设置背景色去模拟间隔线")

        NormalSpacer()
        val show = remember { mutableStateOf(false) }
        Box {
            DropdownMenu(
                show.value,
                { show.value = false },
                offset = DpOffset(0.dp, 10.dp),
            ) {
                DropdownMenuItem(
                    onClick = {},
                    leadingIcon = {
                        Icon(Icons.Filled.Person, "")
                    },
                    text = { Text("登录") },
                    trailingIcon = {
                        Icon(Icons.Filled.Close, "")
                    },
                )
                HorizontalDivider()
                DropdownMenuItem(
                    onClick = {},
                    leadingIcon = {
                        Icon(Icons.Filled.Share, "")
                    },
                    text = { Text("分享") },
                )
            }
            Button({ show.value = true }) {
                Text("显示弹窗")
            }
        }
        UlItem("DropdownMenu")
        LabelText("弹窗，类似PopupWindow")
        OlItem(1,"offset")
        LabelText("设置弹窗偏移量")

        LargeSpacer()
        UlItem("DropdownMenuItem")
        LabelText("弹窗菜单项，可以方便快捷地菜单项")
    }
}